<template>
  <div>

    <a-modal
      :title="title"
      :visible="visible"
      :confirm-loading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
    >
      <div>
        <a-form-model ref="form" :model="form" :rules="rules" :layout="'horizontal'">

          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-model-item label="目录名称" >
                <a-input v-model="projectModalNode.directoryName" placeholder="请输入" disabled/>
              </a-form-model-item>
            </a-col>
          </a-row>

          <a-row :gutter="24">
            <a-col :span="24">
              <a-form-model-item :label="`${type==='t'?'同级':'下级'}目录名称`" prop="directoryName">
                <a-input v-model="form.directoryName" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
          </a-row>

        </a-form-model>
      </div>
    </a-modal>
  </div>
</template>
  <script>
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        form: {
          directoryName: undefined,
          parentId: undefined,
          id: new Date().getTime(),
          children: [],
          projectFileList: []
        },
        rules: {
          directoryName: [
            { required: true, message: '项目名称不能为空', trigger: 'blur' }
          ]
        },
        title: '',
        projectId: '',
        type: ''

      }
    },
    methods: {
      showModal (title, projectId, type, projectModalNode) {
        this.title = title
        this.projectId = projectId
        this.type = type

        console.info(projectModalNode)
        this.projectModalNode = projectModalNode
        this.visible = true
      },
      resetForm () {
        this.form = {
          id: new Date().getTime(),
          directoryName: undefined,
          parentId: undefined,
          children: [],
          projectFileList: []
        }
      },
      handleOk (e) {
        this.confirmLoading = true
        this.$refs.form.validate(valid => {
          if (valid) {
            this.form.parentId = this.projectId

            this.$emit('ok', this.form)
            this.resetForm()
            this.visible = false
            this.confirmLoading = false
          }
        })
      },
      handleCancel (e) {
        console.log('Clicked cancel button')
        this.resetForm()
        this.visible = false
      }
    }
  }
  </script>
